import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "TestPost")
public class TestPost extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Access=Control-Allow-Origin","*");//跨域
        response.setContentType("text/html");//设置响应内容类型
        response.setCharacterEncoding("UTF-8");//指定编码

        //获取前端传入的数据
        BufferedReader br=request.getReader();
        String line;
        StringBuffer stringBuffer=new StringBuffer();
        while ((line=br.readLine())!=null){
            stringBuffer.append(line);
        }
        //设置逻辑实现
        PrintWriter out=response.getWriter();
        String jsonStr="服务器收到信息并返回:  "+stringBuffer.toString();
        out.println(jsonStr);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
